package com.usian.common.all;

import com.usian.utils.threadlocal.ThreadLocalUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ServiceInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String userId = request.getHeader("userId");
        if (userId != null) ThreadLocalUtils.setUserId(Integer.parseInt(userId));
        String refreshToken = request.getHeader("refreshToken");
        if (refreshToken != null)response.addHeader("refreshToken",refreshToken);
        return HandlerInterceptor.super.preHandle(request, response, handler);
    }
}
